#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<int> largestValues(TreeNode* root) {
        vector<int>ret;
        if (root == nullptr) return ret;
        queue<TreeNode*>q;
        q.push(root);
        while (q.size())
        {
            int sz = q.size();
            int m = INT_MIN;
            for (int i = 0; i < sz; i++)
            {
                TreeNode* node = q.front();
                q.pop();
                m = max(m, node->val);
                if (node->left) q.push(node->left);
                if (node->right) q.push(node->right);
            }
            ret.push_back(m);
        }
        return ret;
    }
};